package Object;

import java.util.ArrayList;
import java.util.Scanner;

public class JavaWork2 {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("01,王乐奕,103\t,99\t,123");
        list.add("02,王悦如,122\t,148\t,140");
        list.add("03,韩翌展,110\t,120\t,88");
        list.add("04,马鸣喧,115\t,77\t,97");
        int i;
        do {
            System.out.println("--------欢迎试用成绩查询系统--------");
            System.out.println("1:显示所有成绩\t\t\t\t\t");
            System.out.println("2:学号查询成绩\t\t\t\t\t");
            System.out.println("0:退出查询系统\t\t\t\t\t");
            Scanner sc = new Scanner(System.in);
            System.out.println("请选择:");
            i = sc.nextInt();
            switch (i) {
                case 1:
                    System.out.println("--------查看所有--------");
                    System.out.println("学号\t姓名\t\t语文\t\t数学\t\t英语");
                    showAll(list);
                    break;
                case 2:
                    findDetail(list);
                    break;
                case 0:
                    System.out.println("已退出");
                    break;
            }
        } while (i != 4);
    }
    //showAll 方法
    public static void showAll(ArrayList<String> li1) {
        for (String arr : li1) {
            String[] li2 = arr.split(",");
            for( int i = 0 ; i < li2.length ; i++ ){
                System.out.print(li2[i]+"\t");
            }
            System.out.println();
        }
    }
    //findDetail 方法
    public static void findDetail (ArrayList<String> li3){
        System.out.println("--------成绩查询--------");
        Scanner sc1 = new Scanner(System.in);
        System.out.println("请输入你的学号:");
        String number = sc1.next();
        for (String item : li3) {
            String[] li4 = item.split(",");
            if (number.equals(li4[0])) {
                System.out.println("学号\t姓名\t语文\t数学\t英语");
                System.out.println(item.replace("\t", "")); // 清理制表符
            }
        }
    }
}


